package com.chixing.service.impl;

import com.chixing.mapper.SightsReviewMapper;
import com.chixing.mapper.TravelSightsMapper;
import com.chixing.pojo.TravelSights;
import com.chixing.pojo.TravelSightsExample;
import com.chixing.service.TravelSightsService;
import com.chixing.util.ServerResponse;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TravelSightsServiceImpl implements TravelSightsService {

    @Autowired
    private TravelSightsMapper travelSightsMapper;
    @Autowired
    private SightsReviewMapper sightsReviewMapper;

    //area获取景点列表
    @Override
    public ServerResponse getBySightsArea(String area,Integer pageNum) {
        TravelSightsExample travelSightsExample = new TravelSightsExample();
        travelSightsExample.createCriteria().andTravelSightsLocCityEqualTo(area);
        PageHelper.startPage(pageNum,3);
        List<TravelSights> travelSightsList = travelSightsMapper.selectByExample(travelSightsExample);
        PageInfo<TravelSights> pageInfo = new PageInfo<>(travelSightsList);
        if (travelSightsList != null && travelSightsList.size() > 0){
            return ServerResponse.getSuccess(pageInfo);
        }
        return ServerResponse.getFail(pageInfo);
    }

    @Override
    public ServerResponse getSightsToSales(Integer id) {
        TravelSights travelSights = travelSightsMapper.selectByPrimaryKey(id);
        if(travelSights!=null){
            return ServerResponse.getSuccess(travelSights);
        }else {
            return ServerResponse.getFail(null);
        }
    }
}
